﻿namespace Task11
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    class Task1
    {
        static void Main()
        {
            string inputStrangeNum = Console.ReadLine().ToLower().Trim();

            List<string> strangeNums = new List<string>() { "f", "bIN".ToLower(), "oBJEC".ToLower(), "mNTRAVL".ToLower(), "lPVKNQ".ToLower(), "pNWE".ToLower(), "hT".ToLower() };
            List<char> firstChars = new List<char>() { 'f', 'b', 'o', 'm', 'l', 'p', 'h' };

            List<long> strangeDigits = new List<long>(24);

            string tempDigit = null;
            char firstChary;

            while (inputStrangeNum.Length > 0)
            {
                firstChary = inputStrangeNum[0];
                strangeDigits.Add(firstChars.IndexOf(firstChary));
                tempDigit = strangeNums[firstChars.IndexOf(firstChary)];
                inputStrangeNum = inputStrangeNum.Remove(0, tempDigit.Length);
            }



            int s = 7;
            int d = 10;
            string num = String.Join("", strangeDigits);
            long numAsDecimal = 0;
            for (int i = 0; i < num.Length; i++)
            {
                if (num[num.Length - 1 - i] == '0')
                {
                    numAsDecimal += 0 * CalculatePower(s, i);
                }
                else if (num[num.Length - 1 - i] == '1')
                {
                    numAsDecimal += 1 * CalculatePower(s, i);
                }
                else if (num[num.Length - 1 - i] == '2')
                {
                    numAsDecimal += 2 * CalculatePower(s, i);
                }
                else if (num[num.Length - 1 - i] == '3')
                {
                    numAsDecimal += 3 * CalculatePower(s, i);
                }
                else if (num[num.Length - 1 - i] == '4')
                {
                    numAsDecimal += 4 * CalculatePower(s, i);
                }
                else if (num[num.Length - 1 - i] == '5')
                {
                    numAsDecimal += 5 * CalculatePower(s, i);
                }
                else if (num[num.Length - 1 - i] == '6')
                {
                    numAsDecimal += 6 * CalculatePower(s, i);
                }
                else if (num[num.Length - 1 - i] == '7')
                {
                    numAsDecimal += 7 * CalculatePower(s, i);
                }
                else if (num[num.Length - 1 - i] == '8')
                {
                    numAsDecimal += 8 * CalculatePower(s, i);
                }
                else if (num[num.Length - 1 - i] == '9')
                {
                    numAsDecimal += 9 * CalculatePower(s, i);
                }
                else if (num[num.Length - 1 - i] == 'A')
                {
                    numAsDecimal += 10 * CalculatePower(s, i);
                }
                else if (num[num.Length - 1 - i] == 'B')
                {
                    numAsDecimal += 11 * CalculatePower(s, i);
                }
                else if (num[num.Length - 1 - i] == 'C')
                {
                    numAsDecimal += 12 * CalculatePower(s, i);
                }
                else if (num[num.Length - 1 - i] == 'D')
                {
                    numAsDecimal += 13 * CalculatePower(s, i);
                }
                else if (num[num.Length - 1 - i] == 'E')
                {
                    numAsDecimal += 14 * CalculatePower(s, i);
                }
                else if (num[num.Length - 1 - i] == 'F')
                {
                    numAsDecimal += 15 * CalculatePower(s, i);
                }
            }

            Console.WriteLine(numAsDecimal);

            //List<long> numCompilation = new List<long>();
            //while (numAsDecimal != 0)
            //{
            //    numCompilation.Add((long)(numAsDecimal % d));
            //    numAsDecimal /= d;
            //}

            //numCompilation.Reverse();
            //char[] result = new char[numCompilation.Count];

            //for (int i = 0; i < result.GetLength(0); i++)
            //{
            //    if (numCompilation[i] == 0)
            //    {
            //        result[i] = '0';
            //    }
            //    else if (numCompilation[i] == 1)
            //    {
            //        result[i] = '1';
            //    }
            //    else if (numCompilation[i] == 2)
            //    {
            //        result[i] = '2';
            //    }
            //    else if (numCompilation[i] == 3)
            //    {
            //        result[i] = '3';
            //    }
            //    else if (numCompilation[i] == 4)
            //    {
            //        result[i] = '4';
            //    }
            //    else if (numCompilation[i] == 5)
            //    {
            //        result[i] = '5';
            //    }
            //    else if (numCompilation[i] == 6)
            //    {
            //        result[i] = '6';
            //    }
            //    else if (numCompilation[i] == 7)
            //    {
            //        result[i] = '7';
            //    }
            //    else if (numCompilation[i] == 8)
            //    {
            //        result[i] = '8';
            //    }
            //    else if (numCompilation[i] == 9)
            //    {
            //        result[i] = '9';
            //    }
            //    else if (numCompilation[i] == 10)
            //    {
            //        result[i] = 'A';
            //    }
            //    else if (numCompilation[i] == 11)
            //    {
            //        result[i] = 'B';
            //    }
            //    else if (numCompilation[i] == 12)
            //    {
            //        result[i] = 'C';
            //    }
            //    else if (numCompilation[i] == 13)
            //    {
            //        result[i] = 'D';
            //    }
            //    else if (numCompilation[i] == 14)
            //    {
            //        result[i] = 'E';
            //    }
            //    else if (numCompilation[i] == 15)
            //    {
            //        result[i] = 'F';
            //    }
            //}

            //Console.WriteLine(string.Join("", result));
        }

        public static long CalculatePower(long num, int power)
        {
            long result = 1;
            for (int i = 0; i < power; i++)
            {
                result *= num;
            }

            return result;
        }
    }
}